package com.ddxz.tool.web.dto;

import com.ddxz.tool.core.common.DdxzStatus;
import com.ddxz.tool.core.convert.StringUtil;
import lombok.Data;

import java.io.Serializable;

/**
 * @author 朱宗刚
 * @version 1.0.0
 * @description com.casic.exchange.com.casic.common.tools.dto.CasicResponse
 * @date 2020/2/28
 */

@Data
public class DdxzResponse implements Serializable {
    private static final long serialVersionUID = -5248L;

    private Integer status;

    private String message;

    private Object data;

    private DdxzResponse(Object data) {
        this.data = data;
        this.status = 200;
        this.message = "SUCCESS";
    }

    private DdxzResponse(String message, Object data) {
        this.data = data;
        this.status = 200;
        this.message = message;
    }

    private DdxzResponse(DdxzStatus status, Object... args) {
        this.data = null;
        this.status = status.getStatus();
        this.message = StringUtil.getMessage(status.getMessage(), args);
    }

    public static DdxzResponse correct(Object data) {
        return new DdxzResponse(data);
    }

    public static DdxzResponse correct(String message, Object data) {
        return new DdxzResponse(message, data);
    }

    public static DdxzResponse error(DdxzStatus status, Object... args) {
        return new DdxzResponse(status, args);
    }
}
